//
//  AddItemController.m
//  Product Hunter
//
//  Created by Han Wang on 11/10/11.
//  Copyright (c) 2011 The Masters. All rights reserved.
//

#import "AddItemController.h"

@implementation AddItemController

@synthesize itemName = itemName_;
@synthesize addedFavoriteSearches = addedFavoriteSearches_;

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
        target:self
        action:@selector(cancel:)] autorelease];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave
        target:self
        action:@selector(save:)] autorelease];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

#pragma mark -
#pragma mark Actions

- (IBAction) save: (id)sender {
    [self.addedFavoriteSearches addObject:self.itemName.text];
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction) cancel: (id)sender {
    [self dismissModalViewControllerAnimated:YES];
}


#pragma mark -
#pragma mark Memory management

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

-(void) dealloc{
    [itemName_ release];
    [addedFavoriteSearches_ release];
    [super dealloc];
}

@end
